package bdd.sql.server.bean;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Bean ServerCentral.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "kraken_server_central")
public class ServerCentral {
	
	@Id
	@GeneratedValue
	@Column(name = "servcentr_id")
	private int servcentr_id;
	
	@Column(name = "servcentr_name", nullable = false, updatable = false, unique = true)
	private String servcentr_name;
	
	@Column(name = "servcentr_ip", nullable = false, updatable = false, unique = true)
	private String servcentr_ip;
	
	@Column(name = "cluster_name", nullable = false, updatable = false, unique = true)
	private String servcentr_cluster;
	
	@OneToMany(mappedBy="serveur_central")
    private Set<ServerSite> serverSites;
	
	@OneToOne(mappedBy = "central")
	private ServerStorage serverStorage;

	@ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "id_conf")
	private Configuration central_conf;
	
	/**
	 * Constructeur vide.
	 */
	public ServerCentral(){	}
	
	/**
	 * Créer un nouveau GlobalServer.
	 * @param name
	 * @param ip
	 * @param cluster
	 */
	public ServerCentral(String name, String ip, String cluster){
		this.servcentr_name = name;
		this.servcentr_ip = ip;
		this.servcentr_cluster = cluster;
		
		this.serverSites = new HashSet<ServerSite>();
	}

	public int getServCentr_id() { return servcentr_id;	}
	public void setServCentr_id(int globserv_id) { this.servcentr_id = globserv_id;	}

	public String getServCentr_name() { return servcentr_name;	}
	public void setServCentr_name(String globserv_name) { this.servcentr_name = globserv_name;	}

	public String getServCentr_ip() { return servcentr_ip;	}
	public void setServCentr_ip(String globserv_ip) { this.servcentr_ip = globserv_ip;	}

	public String getServCentr_cluster() { return servcentr_cluster;	}
	public void setServCentr_cluster(String globserv_cluster) { this.servcentr_cluster = globserv_cluster;	}

	public Set<ServerSite> getSiteServers() { return serverSites;	}
	public void setSiteServers(Set<ServerSite> serverSites) { this.serverSites = serverSites;	}
	
	public Set<ServerSite> getServerSites() {	return serverSites;	}
	public void setServerSites(Set<ServerSite> serverSites) {	this.serverSites = serverSites;	}
	public void addServerSite(ServerSite site){	this.serverSites.add(site);	}
	public void delServerSite(ServerSite site){	this.serverSites.remove(site);	}

	public ServerStorage getServerStorage() {	return serverStorage;	}
	public void setServerStorage(ServerStorage serverStorage) {	this.serverStorage = serverStorage;	}
	
	public Configuration getConf() { return central_conf; }
	public void setConf(Configuration central_conf) { this.central_conf = central_conf; }

	@Override
	public String toString() { return getServCentr_name(); }
	
}
